package com.neugh.controller;


import com.neugh.entity.Orde;
import com.neugh.entity.User;
import com.neugh.service.OrdeService;
import com.neugh.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sot
 * @since 2020-05-15
 */
@Controller
public class OrdeController {

    @Autowired
    OrdeService ordeService;

    @Autowired
    ShopService shopService;

    @RequestMapping("/queren1")
    public String queren(Integer id, Model mOdel){
        mOdel.addAttribute("shopa",shopService.selectById(id));
        return "queren";
    }

    @RequestMapping("/tijiao")
    public String tijiao(HttpSession session){
       /* boolean n=ordeService.insertOrde(orderNum,addressId,userId,shopId,orderUme,rPhone,orderPrice,alipayNum);
        if(n){
            return "myinfo";
        }*/
        Orde order1=new Orde();
        User user = (User)session.getAttribute("user");
        Integer userId = user.getUserId();
        order1.setUserId(userId);
        order1.setOrderNum((String) session.getAttribute("saveorderNum"));
        order1.setRPhone((String) session.getAttribute("rPhone"));
        order1.setOrderPrice((String) session.getAttribute("orderPrice"));
        order1.setAddressId((int)session.getAttribute("addressId"));
        order1.setShopId((int)session.getAttribute("shopId"));
        order1.setOrderUme((int)session.getAttribute("orderUme"));
        order1.setAlipayNum((String)session.getAttribute("alipayNum"));
        order1.setOrderStatus("支付成功");
        order1.setOrderTypeId(1);

        //  order.setOrderTime("2015-4-8");
        ordeService.save(order1);
        return "redirect:homepage";
    }

    @ResponseBody
    @GetMapping("order/myorder")
    public List<Orde> myorder(Integer orderTypeId){
        return shopService.selectAllorder(orderTypeId);
    }
}

